//import createjs from "@/../createjs";
import { ViewEvent, manifest } from "../../Const";
import Global from "../../Global";
import BaseModule from "../BaseModule";
import PreloadView from "./PreloadView";

export default class PreloadModule extends BaseModule{
    private _view=new PreloadView()
    init():void{
        console.log('PreloadModule.init')
        this.main.addChild(this._view)
        //加载资源
        //const comp=window.AdobeAn.getComposition("21F88DEE3BA4504D95EDB59DC9A82C68")
        const lib=Global.getLibrary()
        const assets=lib.properties.manifest.concat(manifest)
        const loader=Global.loader
        loader.loadManifest(assets,(loaded,total,evt):void=>{
            const images=Global.getImages()
            if(evt){
                if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
                //if(evt.item.type=="json"){console.log(evt.result)}
                console.log(evt.item.id)
            }
            this._view.setProgress(loaded/total)
        }).then(()=>{
            console.log('加载完成')
            //var lib=comp.getLibrary();
            const ss=Global.getSpriteSheet()
            //var queue = evt.target;
            const ssMetadata = lib.ssMetadata
            for(let i=0; i<ssMetadata.length; i++) {
                //console.log(ssMetadata[i].name)
                ss[ssMetadata[i].name] = new createjs.SpriteSheet( {"images": [loader.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames} )
            }
            this.main.removeChild(this._view)
            this.message.send(ViewEvent.SHOW_HOME_VIEW)
        })
    }
}